package cn.com.sparkle.paxos.event;

import java.util.Set;

import cn.com.sparkle.paxos.ConfigNode;

public abstract class ConfigureEvent implements Event {
	public final static int SENATORS_CHANGE = 2;
	public final static int FOLLOWERS_CHANGE = 3;

	@Override
	public void event(Object... args) {
		int i = (Integer) args[0];
		switch (i) {
		case SENATORS_CHANGE:
			senatorsChange((Set<ConfigNode>) args[1], (Long) args[2]);
			break;
		case FOLLOWERS_CHANGE:
			followersChange((Set<ConfigNode>) args[1]);
			break;
		default:
			throw new RuntimeException("not support event type :" + i);
		}
	}

	public final static void doSenatorsChangeEvent(EventsManager eventsManager,
			Set<ConfigNode> newSenators, long version) {
		eventsManager.doEvent(ConfigureEvent.class, SENATORS_CHANGE,
				newSenators, version);
	}

	public final static void doFollowersChangeEvent(
			EventsManager eventsManager, Set<ConfigNode> newFollowers) {
		eventsManager.doEvent(ConfigureEvent.class, FOLLOWERS_CHANGE,
				newFollowers);
	}

	public abstract void senatorsChange(Set<ConfigNode> newSenators,
			long version);

	public abstract void followersChange(Set<ConfigNode> newFollowers);
}
